import { cloudbaseApp, development } from '@/cloudbaseapi/cloudbase-api'
const db = cloudbaseApp().database()
const { JINWENGDB } = development()
export async function getItems(limit = 10, page = 1) {
  const skip = (page - 1) * limit
  const count = await db.collection(JINWENGDB).count()
  const total = count.total
  const data = await db.collection(JINWENGDB).limit(limit).skip(skip).get()
  data['total'] = total
  return data
}
export async function updateOrAddItem(data, type) {
  const newData = { ...data }
  const id = newData._id
  delete newData['_id']
  delete newData['_openid']
  const res = await db.collection(JINWENGDB).doc(id).set(newData)
  return res
}
export async function delItem(id) {
  const res = await db.collection(JINWENGDB).doc(id).remove()
  return res
}
